#ifndef LIBMAD_STREAM_H
#define LIBMAD_STREAM_H

#include "bit.h"

enum stream_error { 
	
	STREAM_ERROR_NONE	   = 0x0000,	/* no error */
	STREAM_ERROR_BUFLEN	   = 0x0001,	/* input buffer too small (or EOF) */
	STREAM_ERROR_BUFPTR	   = 0x0002,	/* invalid (null) buffer pointer */
	STREAM_ERROR_NODECODE  = 0x0003
	
};


struct bits_stream {
	unsigned char const *buffer;  /* input bitstream buffer */
	unsigned char const *buffer_end;		/* end of buffer */
	struct mad_bitptr ptr;		/* current processing bit pointer */
	unsigned int i_bits;
	enum stream_error error;			/* error code (see above) */
};

void bits_stream_init(struct bits_stream *);
void bits_stream_buffer(struct bits_stream *,unsigned char const *,unsigned long);
unsigned long bits_stream_read(struct bits_stream *,unsigned int);
void bits_stream_skip(struct bits_stream *,unsigned int);
//struct bits_code * bits_stream_decNum(struct bits_stream *stream,struct bits_code *pbitCode,unsigned char ibitCode,unsigned long *p_ulval);
int bits_stream_decXINT32(struct bits_stream *stream,struct bits_code *pbitCode,unsigned char ibitCode,XINT32 *pxval_out,XINT32 *pxval_base,unsigned char bdes);
//unsigned char bits_stream_decode_data(struct bits_stream *stream,unsigned long *p_ulData,struct bits_code *pbitCode,unsigned char ibitCode,unsigned long *pdwbase,unsigned char bReverse);
unsigned long bits_stream_decData(struct bits_stream *stream,struct bits_code *pbitCode,unsigned char ibitCode,unsigned long *p_ulBase,unsigned char bINC);


#endif
